package com.team5101.controller;

import com.team5101.entity.User;
import com.team5101.service.IUserService;
import com.team5101.utils.MD5;
import com.team5101.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    private IUserService userService;
    //从前台拿到phone和password
    @RequestMapping("/look")
    @ResponseBody
   public R userLogin(User user){//从前端拿到uTelephone和uPassword
        System.out.println(user);
        String uPassWord = MD5.MD5Encode(user.getuPassword());
        user.setuPassword(uPassWord);
        User user1 = userService.toLogin(user);
        System.out.println(user1);
      if (user1!=null){
          return R.ok(user1);
      }else {
          return R.error(250,"密码或账户错误");
      }
  }
   @RequestMapping("/see")
   @ResponseBody
   //传入手机号通过手机号拿数据
   public R seeData(String uTelephone){
        System.out.println(uTelephone);
       User user = userService.seeDats(uTelephone);
       return R.ok(user);
   }
   @RequestMapping("/modify")
   @ResponseBody
   //通过手机号修改用户信息
    public R userModify(User user){
       System.out.println(user);
       int i = userService.userModify(user);
       System.out.println(i);
       if (i>0){
           return R.ok();
       }else {
           return R.error(505,"修改失败");
       }
   }

}
